

import 'dart:convert';

import 'package:du_application/http/HttpUtil.dart';
import 'package:du_application/http/Options.dart';
import 'package:du_application/model/CollectModel.dart';
import 'package:du_application/model/ResultModel.dart';
import 'package:du_application/provide/AuthProvider.dart';
import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'package:shared_preferences/shared_preferences.dart';

class CollectProvider with ChangeNotifier {
   CollectModel collectModel;
    Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
    getCollect(context) async {
    await _prefs.then((ins) async{
    Options options =  Options(Provide.value<AuthProvider>(context).token);
   await HttpUtil.getInstance().get("/collect/list",data: {"type":0},options:options.options).then((data) {

     collectModel=CollectModel.fromJson(json.decode(data));
     notifyListeners();
     });
});
  }
    delCollect(context,int valueId) async {
  return  await _prefs.then((ins) async{
    Options options =  Options(Provide.value<AuthProvider>(context).token);
return   await HttpUtil.getInstance().post("/collect/addordelete",data: {"type":0,"valueId":valueId},options:options.options).then((data) {
if(ResultModel.fromJson(json.decode(data)).errno==0){
    getCollect(context);
    notifyListeners();
    return true;
}else{
return false;
} 
});
});
  }
}